﻿//This file is part of Search Engine by Tomasz Kusienicki.
// 
//This Search Engine is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//any later version.
// 
//Foobar is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// 
//You should have received a copy of the GNU General Public License
//on <http://www.gnu.org/licenses/>.

namespace AdminApp1.Common
{
    /// <summary>
    /// Abstract presenter base
    /// </summary>   
    public abstract class PresenterBase<TView, TPresenter>
        where TView : ViewBase<TView, TPresenter>
        where TPresenter : PresenterBase<TView, TPresenter>
    {
        #region Constructor (ViewBase)
        public TView View { get; private set; }
        protected PresenterBase(TView view)
        {
            View = view;
        }
        #endregion
        
        #region (virtual) Initialize // View.Presenter = this as PresenterBase
        public virtual void Initialize()
        {
            View.Presenter = this as TPresenter;
        }
        #endregion
    }

    /// <summary>
    /// Abstract presenter base
    /// </summary>   
    public abstract class PresenterBase<TView, TPresenter, TModel> : PresenterBase<TView, TPresenter>
        where TView : ViewBase<TView, TPresenter, TModel>
        where TPresenter : PresenterBase<TView, TPresenter, TModel>
        where TModel : ModelBase<TModel>
    {
        #region Constructor (ViewBase, ModelBase)
        public TModel Model { get; private set; }
        protected PresenterBase(TView view, TModel model)
            : base(view)
        {
            Model = model;
        }
        #endregion

        #region (override + base) Initialize // View.Model = this.Model
        public override void Initialize()
        {
            base.Initialize();
            View.Model = Model;
        }
        #endregion
    }
}